/*
 * @Author: C.
 * @Date: 2023-03-14 14:58:07
 */
import { onMounted } from 'vue';
import { BasicTableProps } from '/@/components/Table';
import { useModal, UseModalReturnType } from '/@/components/Modal';
import { getFormMaps } from '/~/utils/help/createFields';
import type { DynamicProps } from '/#/utils';

type Props = Partial<DynamicProps<BasicTableProps>>;

export function useTableModel(props?: Props): UseModalReturnType {
  const [registerModal, modelAction] = useModal();
  onMounted(() => {
    modelAction.openModal(false, {
      init: true,
      useSearchForm: true,
      showTableSetting: false,
      scroll: { y: 500 },
      showIndexColumn: false,
      rowSelection: {
        type: 'checkbox',
      },
      formConfig: {
        labelWidth: 120,
        schemas: getFormMaps(['Keyword']),
      },
      ...props,
    });
  });
  return [registerModal, modelAction];
}
